package com.mars.module.admin.controller;


import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import com.mars.common.enums.BusinessType;
import com.mars.common.result.R;
import com.mars.common.util.ExcelUtils;
import io.swagger.annotations.Api;
import com.mars.framework.annotation.RateLimiter;
import com.mars.module.admin.entity.SysUserLike;
import com.mars.framework.annotation.Log;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import com.mars.common.response.PageInfo;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;
import com.mars.module.admin.service.ISysUserLikeService;
import com.mars.module.admin.request.SysUserLikeRequest;

import javax.servlet.http.HttpServletResponse;

/**
 * 用户点赞控制层
 *
 * @author mars
 * @date 2024-04-04
 */
@Slf4j
@AllArgsConstructor
@RestController
@Api(value = "用户点赞接口管理",tags = "5.用户点赞接口管理")
@RequestMapping("/admin/sysUserLike" )
public class SysUserLikeController {

    private final ISysUserLikeService iSysUserLikeService;

    /**
     * 分页查询用户点赞列表
     */
    @ApiOperation(value = "分页查询用户点赞列表")
    @PostMapping("/pageList")
    public R<PageInfo<SysUserLike>> pageList(@RequestBody SysUserLikeRequest sysUserLikeRequest) {
        return R.success(iSysUserLikeService.pageList(sysUserLikeRequest));
    }

    /**
     * 获取用户点赞详细信息
     */
    @ApiOperation(value = "获取用户点赞详细信息")
    @GetMapping(value = "/query/{id}")
    public R<SysUserLike> detail(@PathVariable("id") Long id) {
        return R.success(iSysUserLikeService.getById(id));
    }

    /**
     * 新增用户点赞
     */
    @Log(title = "新增用户点赞", businessType = BusinessType.INSERT)
    @RateLimiter
    @ApiOperation(value = "新增用户点赞")
    @PostMapping("/add")
    public R<Void> add(@RequestBody SysUserLikeRequest sysUserLikeRequest) {
        iSysUserLikeService.add(sysUserLikeRequest);
        return R.success();
    }

    /**
     * 修改用户点赞
     */
    @Log(title = "修改用户点赞", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改用户点赞")
    @PostMapping("/update")
    public R<Void> edit(@RequestBody SysUserLikeRequest sysUserLikeRequest) {
        iSysUserLikeService.update(sysUserLikeRequest);
        return R.success();
    }

    /**
     * 删除用户点赞
     */
    @Log(title = "删除用户点赞", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除用户点赞")
    @PostMapping("/delete")
    public R<Void> remove(@RequestParam(value = "id") String id) {
        iSysUserLikeService.deleteByCommunity(id);
        return R.success();
    }

    /**
    * 导出用户点赞
    *
    * @param response response
    * @throws IOException IOException
    */
    @PostMapping(value = "/export")
    public void exportExcel(HttpServletResponse response,@RequestBody SysUserLikeRequest sysUserLikeRequest) throws IOException {
        List<SysUserLike> list = iSysUserLikeService.list(sysUserLikeRequest);
        ExcelUtils.exportExcel(list, SysUserLike.class, "用户点赞信息", response);
    }
}
